<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>齐鲁工业大学图书馆预约系统 API</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap');

        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        body {
            font-family: 'Poppins', sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }

        .container {
            background-color: #ffffff;
            border-radius: 20px;
            box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22);
            padding: 40px;
            width: 100%;
            max-width: 800px;
        }

        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
        }

        h1 {
            color: #333;
            font-weight: 600;
        }

        h2 {
            color: #3498db;
            margin-top: 20px;
            margin-bottom: 15px;
        }

        p {
            margin-bottom: 15px;
            line-height: 1.6;
            color: #555;
        }

        pre {
            background-color: #f0f0f0;
            border-radius: 8px;
            padding: 15px;
            overflow-x: auto;
            font-size: 14px;
            line-height: 1.4;
            margin-bottom: 20px;
        }

        code {
            font-family: 'Courier New', Courier, monospace;
        }

        .config-link {
            width: 50px;
            height: 50px;
            background-color: #3498db;
            color: white;
            text-decoration: none;
            border-radius: 50%;
            display: flex;
            justify-content: center;
            align-items: center;
            transition: background-color 0.3s ease, transform 0.3s ease;
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
        }

        .config-link:hover {
            background-color: #2980b9;
            transform: scale(1.1);
        }

        .config-link i {
            font-size: 20px;
        }

        .response-section {
            background-color: #f9f9f9;
            border-left: 4px solid #3498db;
            padding: 15px;
            margin-bottom: 20px;
            border-radius: 0 8px 8px 0;
        }

        .highlight {
            color: #e74c3c;
            font-weight: bold;
        }

        .note {
            background-color: #fffbea;
            border-left: 4px solid #f1c40f;
            padding: 10px 15px;
            margin: 20px 0;
            border-radius: 0 8px 8px 0;
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .container > * {
            animation: fadeIn 0.5s ease-out forwards;
            opacity: 0;
        }

        .container > *:nth-child(1) { animation-delay: 0.1s; }
        .container > *:nth-child(2) { animation-delay: 0.2s; }
        .container > *:nth-child(3) { animation-delay: 0.3s; }
        .container > *:nth-child(4) { animation-delay: 0.4s; }
        .container > *:nth-child(5) { animation-delay: 0.5s; }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1>齐鲁工业大学图书馆预约系统 API</h1>
            <a href="/config" class="config-link" title="生成配置文件">
                <i class="fas fa-cog"></i>
            </a>
        </div>
        <p>欢迎使用齐鲁工业大学图书馆预约系统 API。该 API 允许您使用学号和密码直接获取授权 Token。</p>
        
        <div class="note">
            <strong>重要提示：</strong> 本 API 仅供学习和个人使用，请勿用于任何违反校规或侵犯他人权益的行为。
        </div>
        
        <h2>API 端点</h2>
        <p>登录 API 的端点为：<code id="apiEndpoint"></code></p>
        
        <h2>请求方法</h2>
        <p>使用 <strong>POST</strong> 方法发送请求。</p>
        
        <h2>请求头</h2>
        <p>请确保包含以下请求头：</p>
        <pre><code>Content-Type: application/json
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36</code></pre>
        
        <h2>请求体</h2>
        <p>请求体应为 JSON 格式，包含以下字段：</p>
        <pre><code>{
    "username": "你的学号",
    "password": "你的密码"
}</code></pre>
        
        <h2>响应格式</h2>
        <p>成功响应示例：</p>
        <div class="response-section">
            <pre><code>{
    "success": true,
    "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...",
    "user_info": {
        "id": "2022xxxxxx",
        "name": "张三",
        "card": "2022xxxxxx",
        "roleName": "学生",
        "deptName": "计算机学院"
    }
}</code></pre>
        </div>
        
        <p>失败响应示例：</p>
        <div class="response-section">
            <pre><code>{
    "success": false,
    "message": "登录失败，未获取到有效认证信息"
}</code></pre>
        </div>
        
        <h2>使用 Token</h2>
        <p>获取到的 token 可以在后续请求中用于身份验证，通常放在 HTTP 请求头的 <code>Authorization</code> 字段中：</p>
        <pre><code>Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...</code></pre>
        
        <h2>cURL 示例</h2>
        <pre><code id="curlExample"></code></pre>
        
        <h2>JavaScript 示例</h2>
        <pre><code>fetch("<span id="jsApiEndpoint"></span>", {
    method: "POST",
    headers: {
        "Content-Type": "application/json",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
    },
    body: JSON.stringify({
        username: "你的学号",
        password: "你的密码"
    })
})
.then(response => response.json())
.then(data => {
    if (data.success) {
        console.log("登录成功，Token:", data.token);
        console.log("用户信息:", data.user_info);
    } else {
        console.error("登录失败:", data.message);
    }
})
.catch(error => console.error("请求出错:", error));</code></pre>

        <div class="note">
            <strong>安全提示：</strong> 请确保在安全的环境中使用该 API，避免在公共场所或不安全的网络中传输您的凭据。Token 应妥善保管，不要泄露给他人。
        </div>
    </div>

    <script>
        function getBaseUrl() {
            return window.location.protocol + "//" + window.location.host;
        }

        function updateApiEndpoint() {
            const baseUrl = getBaseUrl();
            const apiEndpoint = baseUrl + '/login';
            document.getElementById('apiEndpoint').textContent = apiEndpoint;
            document.getElementById('jsApiEndpoint').textContent = apiEndpoint;
        }

        function updateCurlExample() {
            const baseUrl = getBaseUrl();
            const apiEndpoint = baseUrl + '/login';
            const curlExample = `curl --location --request POST '${apiEndpoint}' \\
--header 'Content-Type: application/json' \\
--header 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36' \\
--data-raw '{
    "username": "你的学号",
    "password": "你的密码"
}'`;
            document.getElementById('curlExample').textContent = curlExample;
        }

        // 在页面加载完成后更新内容
        window.onload = function() {
            updateApiEndpoint();
            updateCurlExample();
        };
    </script>
</body>
</html>